<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>title</title>
    <link href="resource/style.css" rel="stylesheet" type="text/css">
    <script src="resource/jquery214.js"></script>
    <script src="resource/fastclick.js"></script>
    <script src="resource/zeptomin.js"></script>
    <script src="resource/picker.js"></script>
    <script src="../script/api.js"></script>
    <script src="resource/md5.js"></script>
    <script type="text/javascript" src="../script/constants.js"></script>
    <script type="text/javascript" src="../script/aes.js"></script>
    <script type="text/javascript" charset="UTF-8" src="../script/naes.js"></script>
    <script type="text/javascript" src="../script/modeecb.js"></script>
    <script src="../script/tmd5.js"></script>
    <style>
    	body{
    		background: #2b7ca6;
    		background-size:cover;
    	}
    	.login{
    	    width: 80%;
    	    background: rgba(255,255,255,0.5);
    	    margin: 0 auto;
    	    border-radius:10px;
    	}
    	input::-webkit-input-placeholder {
         /* placeholder颜色  */
         color: #FFFFFF;
     }
    </style>
</head>
<body>
    <div style="float: left;margin-top: 20px;width: 100%;"><img style="width: 10%;" src="../image/back.png" onclick="closeWd();"/></div>
    <div style="clear: both;"></div>
	<div style="color: #fff;width: 100%;text-align: center;font-size: 40px;margin-top: 100px;margin-bottom: 40px;">
    金穗服务
	</div>
	 <input name="md5_passwd" id="md5_passwd" type="hidden" />
	 <div id="fixiosstatusbardiv" style="display:none;height:10px;position:relative;top:0;left:0;right:0;background-color:#dfdfdf"></div>
	<div class="login">
	<div style="clear:both;width:100%;text-align: center;font-size: 12px;color:red;" id="wrong"></div>
	   <div style="width: 100%;height: 60px;margin: 0 auto;">
	     <div style="float: left;width:40px;height: 40px;margin-top: 10px;margin-left: 10px;">
	        <img style="width:100%;" src="../image/tabBar/user.png" />
	     </div>
	     <div style="float: right;margin-right: 20px;width: 70%;margin-top: 10px;">
	        <input type="text" id="phone" name="phone" placeholder="请输入手机号" style="height: 30px;width: 100%;background-color: transparent;color: #fff;border-top: 0px;border-left: 0px;border-right: 0px;outline:none;font-size: 18px;"/>
	     </div>
	   </div>
	   
	   <div style="width: 100%;height: 60px;margin: 0 auto;">
	     <div style="float: left;width:40px;height: 40px;margin-top: 10px;margin-left: 10px;">
	        <img style="width:100%;" src="../image/tabBar/pwd.png" />
	     </div>
	     <div style="float: right;margin-right: 20px;width: 70%;margin-top: 10px;">
	        <input type="password" id="passwd" name="passwd" placeholder="请输入密码" style="height: 30px;width: 100%;background-color: transparent;color: #fff;border-top: 0px;border-left: 0px;border-right: 0px;outline:none;font-size: 18px;"/>
	     </div>
	   </div>
	   
	   <div style="width: 100%;height: 60px;margin: 0 auto;display: none;" id="checkNum">
	     <div style="float: left;height: 40px;margin-top: 10px;margin-left: 10px;color: #fff;font-size: 18px;">
	        请输入验证码
	     </div>
	     <div style="float: right;margin-right: 20px;width: 45%;margin-top: 10px;">
	        <input type="text" id="yzm" name="yzm" style="height: 30px;width: 100%;background-color: transparent;color: #fff;border-top: 0px;border-left: 0px;border-right: 0px;outline:none;font-size: 18px;"/>
	     </div>
	   </div>
	</div>
	
    <div id="submit" style="padding-top: 20px;width:100%;text-align: center;" tapmode="presshover">
	   <div  onclick="dl()" style="width:80%;height:40px;background: #5CACEE;margin:0 auto;color:#fff;line-height: 40px;border-radius:5px;font-size: 18px;">登录</div>
    </div>
    <div style="padding-top: 10px;padding-bottom20px;width:100%;text-align: center;" tapmode="presshover">
	   <div  style="width:80%;height:40px;margin:0 auto;color:#fff;line-height: 35px;border-radius:5px;">
	     <div onclick="mmzh()" style="width:48%;height:40px;float: left;color:#fff;line-height: 40px;border-radius:5px;font-size: 18px;color: #ffffff;text-decoration:underline">忘记密码</div>
	     <div onclick="zc()" style="width:48%;height:40px;float: right;color:#fff;line-height: 40px;border-radius:5px;font-size: 18px;color: #ffffff;text-decoration:underline">用户注册</div>
	   </div>
    </div>
    
    <div style="position: relative;margin-top: 50px;width: 100%;text-align: center;color: #ffffff;font-size: 14px;margin-bottom: 20px;">
      四川航天信息有限公司
    </div>
    <input type="hidden" id="status"/>
    <div id="loadingToast" style="display:none;">
			<div class="weui-mask_transparent"></div>
			<div class="weui-toast">
				<i class="weui-loading weui-icon_toast"></i>
				<p class="weui-toast__content">数据加载中...</p>
			</div>
		</div>
</body>
<script type="text/javascript">
apiready = function(){
    $("#status").val("0");
    api.parseTapmode();
    api.sendEvent({
	    name: 'closeLock'
	});
}


function closeWd(){
   api.closeWin();
}

function back(){
	api.sendEvent({
	    name:'reloadIndex'
    });
    api.closeWin({});
}

function mmzh(){
  api.openWin({
	  name: 'resetPwd',
	  url: './mmzh.html'
  });
}

function zc(){
  api.openWin({
	  name: 'register',
	  url: './register.html'
  });
}

  function check0(){
    var phone = document.getElementById("phone").value;
    var passwd = document.getElementById("passwd").value;
    var passwd = hex_md5(passwd);

    if(!(/^1[3|4|5|7|8][0-9]\d{4,8}$/.test(phone))){//验证手机号
      api.alert({msg:'输入正确手机号'});
      return false;
    } 
    document.getElementById("md5_passwd").value = passwd ;
    return true;
  }


  function dl() {	
     var uiId;
     var UILoading = api.require('UILoading');
		UILoading.flower({
		    center: {
		        x: api.winWidth/2.0,          
		        y: api.winHeight/2.0 
		    },
		    size: 30,
		    mask: "rgba(0,0,0,0.5)",
		    fixed: true
		}, function(ret) {
		    //alert(JSON.stringify(ret));
		    uiId = ret.id;
		});
     var intervalTime = parseInt(new Date().getTime())-parseInt($api.getStorage("wrongTime"));
     if(intervalTime < 180000 && parseInt($api.getStorage("wrongNum")) == 5){
       $("#wrong").hide();
       alert("错误次数过多，请"+parseInt(180-intervalTime/1000)+"秒后重新登录");
       UILoading.closeFlower({
		    id: uiId
		});
       return;
     }else if(intervalTime >= 180000){
       $api.rmStorage("wrongTime");
       $api.rmStorage("wrongNum");
     }
  	 var phone = document.getElementById("phone").value;
     var passwd = document.getElementById("passwd").value;
     var passwd = md5(passwd);
	 document.getElementById("md5_passwd").value = passwd ;
	 var md5_passwd = document.getElementById("md5_passwd").value;
     var a = check0();
     if(a){
      var callback = function(ret, err){
       var rodm = ret.salt;
      if( rodm == ""){
         alert("服务器异常！");
         return;
      }
      var salt = api.loadSecureValue({
	       sync: true,
	       key: 'salt'
	  });
      md5_passwd = md5(md5_passwd+salt);
      var ppd = md5_passwd;
      md5_passwd = md5(md5_passwd+rodm);
      var deviceId = api.deviceId;
	  var deviceModel = api.deviceModel; 
	  var deviceName = api.deviceName;
	  api.require('ipAddress').getIp(
	  function(re, err) {
	  var status = $("#status").val(); //更换设备登录后status为1
	  var yzm = document.getElementById("yzm").value;
	  var content = {"openid":"","phone":phone,"md5_passwd":md5_passwd,"deviceId":deviceId,"deviceModel":deviceModel,"deviceName":deviceName,"ip":re.ip,"status":status,"yzm":yzm};
      var call = function(ret, err){
            //console.log(JSON.stringify(ret));
             UILoading.closeFlower({
			    id: uiId
			});
		   if(ret){
                if (ret.flag=='Y') {
                    var aeskey = api.loadSecureValue({
					   sync: true,
					   key: 'aeskey'
				    });
				    if(ret.dl!=null&&ret.dl!=''){
				        var res = eval("("+Decrypt(ret.dl,aeskey)+")");
		    			var id = res.id;
		    			var _openid = res.openid;
		    			var YHDJ = "";
		    			if(typeof(res.level) == "undefined" || res.level == "undefined"){
		    			   YHDJ = "平台会员";
		    			}else{
		    			   YHDJ = res.level;
		    			}
                        $api.setStorage('openid',_openid);
		    			$api.setStorage("loginid",id);
		    			$api.setStorage("dl_phone",phone) ;
		                var lgtime = new Date().getTime();
		                $api.setStorage("lgtime",lgtime);
		                $api.setStorage("LOGIN_FLAG","Y");
		                $api.setStorage("YHDJ",YHDJ);
		                if($api.getStorage("chartPwd") == "EXIT"){
		                   $api.setStorage("chartPwd",true);
		                }
						api.sendEvent({
			                name:'reloadIndex'
		                });
		                api.sendEvent({
			                name:'reloadUserinfo'
		                });
		                if($api.getStorage("cpe") != phone){
				            ppd = Encrypt(ppd,aeskey);
				            $api.setStorage("cpd",ppd);
	                        $api.setStorage("cpe",phone);
	                        api.sendEvent({
				                name:'chartLock'
			                });
		                }
		                if(typeof($api.getStorage("chartWrong")) != "undefined"){
		                   $api.rmStorage("chartWrong");
		                }
		                api.closeWin();
		       		 }else {
		       		    var wn = wrong();
		       		    api.alert({msg:"用户名或密码错误"});
		       		 }
       		 	 }else if(ret.flag=='S'){
       		 	    var wn = wrong();
       		 	    api.alert({msg:"用户名或密码错误"});
       			 }else if(ret.flag=='C'){
       			    api.alert({msg:"检测到您正在使用另一台设备登录，请输入验证码完成登录，验证码会以短信形式发送到您的登录手机号"});
                    $("#status").val(1);
                    $("#checkNum").show();
                    $("#yfg").show();
       			 }else if(ret.flag=='W'){
       			    api.alert({msg:"验证码输入有误"});
       			    $("#status").val(1);
                    $("#checkNum").show();
                    $("#yfg").show();
       			 }else{
       			    var wn = wrong();
       			    api.alert({msg:"用户名或密码错误"});
       			 }
       		 }else{
       		 	api.alert({msg:'网络异常'});
       		 }
      }
      encApiAjax(JSON.stringify(content),url.yhdl1,call);
	  });
    }
    var parameter = {};
    apiAjax(JSON.stringify(parameter),url.salt,callback);
    }else{
      UILoading.closeFlower({
		    id: uiId
		});
    }
  }
  
  
  function wrong(){
    var wn = 0;
    if(typeof($api.getStorage("wrongNum")) == "undefined"){
      var time = new Date().getTime();
      $api.setStorage("wrongNum",1);
      $api.setStorage("wrongTime",time);
      wn = 4;
    }else{
      var wrongNum = parseInt($api.getStorage("wrongNum"))+1;
      $api.setStorage("wrongNum",wrongNum);
      wn = 5-wrongNum;
    }
    document.getElementById("wrong").innerHTML = "剩余登录次数"+wn+"次";
    $("#wrong").show()
  }
  
</script>
</html>